<?php

namespace app\aiv110\controller;

use app\aiv110\controller\CommonController;
use think\Validate;
use think\Db;
use app\util\Utils;

class BigbrandController extends CommonController {
    /*
     * code列表
     */

    public function code() {
        /*
         * 0  成功
         * 1  参数错误
         * 2  验证失败
         * 110000  
         * 110001  
         * 110002  
         * 110003
         * 110004
         */
    }

    /*
     * 想要（大牌商品）
     * author xfwed 
     * date 2020.12.01
     * 
     */

    public function wantBigBrand() {
        $rule = [
            'ctmId' => 'require',
            'goodsId' => 'require',
        ];
        $msg = [
            'ctmId.require' => '用户id必须',
            'goodsId.require' => '商品id必须',
        ];

        $all = input('param.');

        $validate = new Validate($rule, $msg);
        if (!$validate->check($all)) {
            $error = $validate->getError();

            return Utils::ajaxReturn(1, $error, null);
        }
        $ctmId = $all['ctmId'];
        $goodsId = $all['goodsId'];
        $wantRow = Db::table('goods_want')
                ->where('ctm_id',$ctmId)
                ->where('goods_id',$goodsId)
                ->find();
        if($wantRow){
            return Utils::ajaxReturn(110000, '请勿重复操作', NULL);
        }
        
        $goods_name = Db::table('goods_info')->where('id',$goodsId)->value('name');
        $data['ctm_id'] = $ctmId;
        $data['goods_id'] = $goodsId;
        $data['goods_name'] = $goods_name;
        $data['add_time'] = date('Y-m-d H:i:s',  time());
        Db::table('goods_want')->insert($data);
        
        return Utils::ajaxReturn(0, '添加成功', null);
    }
    
    /*
     * 活动页面-商品列表
     * author xfwed 
     * date 2021.1.19
     * 
     */

    public function miaoshaGoodsList() {
        $list = Db::table('goods_info')->alias('g')
                ->join(['goods_info_detail'=>'gid'],'gid.goodsId = g.id','left')
                ->join(['brand_info'=>'bi'],'bi.id = g.brandId','left')
                ->field('g.id,g.name,g.icon,gid.oriPrice,gid.price,bi.name brandName')
                ->where('g.id','in','386,577,494,596,434,539,683,391,593,597,416,687')
                ->order('gid.price asc')
                ->select();
        
        return Utils::ajaxReturn(0, '查询成功', $list);
    }
    
    /*
     * 新年活动-商品列表
     * author xfwed 
     * date 2021.1.27
     * 
     */

    public function newYearGoodsList() {
        if(time() > 1615392000){ //1615392000
            return Utils::ajaxReturn(1, '活动已结束', null);
        }
        $list = Db::table('goods_info')->alias('g')
                ->join(['goods_info_detail'=>'gid'],'gid.goodsId = g.id','left')
                ->join(['brand_info'=>'bi'],'bi.id = g.brandId','left')
                ->field('g.id,g.name,g.icon,gid.oriPrice,gid.price,gid.name detailName,bi.name brandName')
                ->where('g.id','in','596,585,45,676,529,620,616,599')
                ->order('gid.price asc')
                ->group('g.id')
                ->select();
        
        return Utils::ajaxReturn(0, '查询成功', $list);
    }
    
    /*
     * 端午节活动-商品列表
     * author xfwed 
     * date 2021.06.09
     * 
     */

    public function dragonGoodsList() {
        $list = Db::table('goods_info')->alias('g')
                ->join(['goods_info_detail'=>'gid'],'gid.goodsId = g.id','left')
                ->field('g.id,g.name,g.icon,gid.oriPrice,gid.price,gid.name detailName')
                ->where('g.id','in','370,741,600,593,595,740,739,582,541,706,529')//  736,599,595,370,593
                ->order('gid.price asc')
                ->group('g.id')
                ->select();
        $data['img']= 'http://47.104.83.107/images/kkmimg/kkmai/default/duanwujieliebiao.png';
        $data['list'] = $list;
        
        return Utils::ajaxReturn(0, '查询成功', $data);
    }
    
}
